﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.BLL
{
    public class Department
    {
        #region 字段 属性

        private int mDepartmentNum;

        public int DepartmentNum
        {
            get { return mDepartmentNum; }
            set { mDepartmentNum = value; }
        }

        private string mDepartmentName;

        public string DepartmentName
        {
            get { return mDepartmentName; }
            set { mDepartmentName = value; }
        }

        private string mDepartmentCode;

        public string DepartmentCode
        {
            get { return mDepartmentCode; }
            set { mDepartmentCode = value; }
        }

        #endregion

        private IDepartmentDAL departmentDAL;

        public Department()
        {
            departmentDAL = Adapter.GetDepartment();
        }

        public void FetchObject(IDataReader dr)
        {
            if (dr!=null)
            {
                mDepartmentNum = ConvertDataType.CheckFiledInt(dr["department_num"]);
                mDepartmentName = ConvertDataType.CheckFiledString(dr["department_name"]);
                mDepartmentCode = ConvertDataType.CheckFiledString(dr["department_code"]);
            }
        }

        public  DataTable Display()
        {
            return departmentDAL.Select();
        }

        public  bool CreateDepartment(Department department)
        {
            return departmentDAL.Insert(department.mDepartmentName, department.mDepartmentCode) > 0 ? true : false;
        }

        public  bool SetDepartment(Department department)
        {
            return departmentDAL.Update(department.mDepartmentNum, department.mDepartmentName, department.mDepartmentCode) > 0 ? true : false;
        }

        public  bool RemoveDepartment(int departmentNum)
        {
            return departmentDAL.Delete(departmentNum) > 0 ? true : false;
        }
    }
}
